package com.t;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DataServlet01 extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public DataServlet01() {
    }
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("connected");
		} catch (ClassNotFoundException e) {
			System.out.println("failed");
			e.printStackTrace();
		}
		try {
			Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_mytest01","w5yj2myxwk", "l04zz2k0lh4ymhhyk5kkk4555w5zyw0x0whk0i0l");
			Statement st=(Statement)con.createStatement();
			ResultSet rs=(ResultSet)st.executeQuery("select * from one");
			resp.setContentType("text/html;charset=utf-8");
			PrintWriter out=resp.getWriter();
			out.println("My first servlet");
			System.out.println("1234");
			while(rs.next()){
				String a=rs.getString("name");
				String b=rs.getString("gender");
				out.println(a);
				out.println(b);	
			}
			con.close();
			st.close();
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}
